//
// Created by xili on 2024/7/31 9:49.
// Go big or go home.
//
#include <vector>

using namespace std;

class MyCircularDeque {
public:
    MyCircularDeque(int k) {
        deq.resize(k);
        head = 0;
        tail = 0;
        count = 0;
        size = k;
    }

    bool insertFront(int value) {
        if (isFull()) {
            return false;
        }
        deq[head] = value;
        count++;
        head = (head - 1 + size) % size;
        return true;
    }

    bool insertLast(int value) {
        if (isFull()) {
            return false;
        }
        deq[tail] = value;
        count++;
        tail = (tail + 1) % size;
        return true;
    }

    bool deleteFront() {
        if (isEmpty()) {
            return false;
        }
        head = (head + 1) % size;
        count--;
        return true;
    }

    bool deleteLast() {
        if (isEmpty()) {
            return false;
        }
        tail = (tail - 1 + size) % size;
        count--;
        return true;
    }

    int getFront() {
        if (isEmpty()) {
            return -1;
        }
        return deq[(head + 1) % size];
    }

    int getRear() {
        if (isEmpty()) {
            return -1;
        }
        return deq[(tail - 1 + size) % size];
    }

    bool isEmpty() {
        return count == 0;
    }

    bool isFull() {
        return count == deq.size();
    }

private:
    vector<int> deq;
    int head;
    int tail;
    int count;
    int size;
};

/**
 * Your MyCircularDeque object will be instantiated and called as such:
 * MyCircularDeque* obj = new MyCircularDeque(k);
 * bool param_1 = obj->insertFront(value);
 * bool param_2 = obj->insertLast(value);
 * bool param_3 = obj->deleteFront();
 * bool param_4 = obj->deleteLast();
 * int param_5 = obj->getFront();
 * int param_6 = obj->getRear();
 * bool param_7 = obj->isEmpty();
 * bool param_8 = obj->isFull();
 */